(defun primep(n)
  (cond 
    ((< n 0) (primep (- n)))
    ((= n 1) nil)
    ((or (<= n 3) (= n 5) (= n 7) (= n 11)) t)
    ((or (= n 4) (= n 6) (= n 8) (= n 9)) nil)
    ((zerop (mod n 2)) nil)
    (t (loop 
	  for i = 3 then (+ 2 i) 
	  with lim = (sqrt n) 
	  while (<= i lim) 
	  when (zerop (mod n i)) do (return nil) 
	  finally (return t)))))

(defun permutations (items &aux result)
   (if items
       (dolist (item items result)
        (dolist (permutation (permutations (remove item items)))
          (push (cons item permutation) result)))
       '(nil)))

(defun make-no-with-range(n digits)
  (cond ((= digits 1) (car n))
	((or (null n) (< digits 1)) 0)
	(t (+ (* (car n) (expt 10 (1- digits))) (make-no-with-range (cdr n) (1- digits))))))

(defun make-no(n)
  (make-no-with-range n (length n)))

(defun probl41()
    (loop for i in (delete-if-not #'primep (mapcar #'make-no (permutations '(1 2 3 4 5 6 7)))) maximize i))